package com.uwang.library.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.alibaba.fastjson.JSON;
import com.uwang.library.model.MemberListModel;
import com.uwang.library.service.MemberListService;
import com.uwang.library.service.impl.MemberListServiceImpl;

@WebServlet("/memberList")
public class MemberList extends HttpServlet{
	
	private static final long serialVersionUID = 1L;
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doGet(req, resp);
	}
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		MemberListService memberListService = new MemberListServiceImpl();
		List<MemberListModel> memberList =  memberListService.getAllMember();
		HttpSession session=req.getSession();
		session.setAttribute("memberList", JSON.toJSONString(memberList));
		req.getRequestDispatcher("/member-list.jsp").forward(req, resp);
	}
	
	public static void main(String[] args) {
	}
}
